import { loginServer } from "@/common/index"
import {global, piniaStore} from "@/utils/index"
import { basicServer } from "@/common/index"

	// 获取token
	export const httpGetToken = async ({code}) => {
		try{
			const res = await loginServer.login({code});
			if(res.code === 200){
				global.saveTokenToLocal(res.data);
				basicServer.queryUerInfoAndToSave();
				return true;
			} else {
				console.log(res)
				return false;
				
			}
		}catch(e){
			console.log(e)
			return false;
		}
	}
	
	// 获取token
	export const httpToken = async () => {
		if(!global.getToken()){
			return uni.login({
				provider:"weixin",
				 success(res) {
					if(res?.errMsg === "login:ok"){
						httpGetToken({code: res.code})
					}
				},
				fail(res) {
					console.log('fail', res)
				}
			})
		}
	}


// 获取用户信息，并存储起来
export const queryUerInfoAndToSave = async () => {
	
}